<?php
include "setup.php";
include "library.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="imagetoolbar" content="no" />
<title>TPGallery</title>
<style type="text/css">
<!--
body{
	background-color: #D0D0D0;
}
a:link{color:#666;text-decoration:none}
a:visited{color:#666;text-decoration:none}
a:active{color:#666;text-decoration:none}
a:hover{color:#000;text-decoration:none}
#gallery {
	border-collapse:collapse;
	border:0;
}
#gallery .gimg {
	border:1px solid #CCC;
	background:#FFF;
	padding:3px;
	margin-bottom:4px;
}
#gallery .label {
	margin: 0 0 8px 0;
	color:#CC3300;
}
#gallery .exif {
	font-size:9pt;
	text-align:left;
	color:#385F7E;
	margin: 0 0 4px 0;
}
-->
</style>
</head>
<body>
<?php

	// 파라메터 처리
	$path = $_GET['path'];
	$name = $_GET['name'];
	if ($path == "") $path="/";
	
	// Filter
	$path = str_replace("..","",$path);

	$dir_path = $tpg_config["prefix_photo_dir"].$path;

	// JPG 파일의 목록 얻기
	$dir_handle = @opendir($dir_path) or die("파일목록 얻기에 실패했습니다.");
	// 이전이미지, 현재이미지, 다음이미지 구하기
	$prevfile = "";
	$nextfile = "";
	$file = "";
	while(($filename=readdir($dir_handle))!=FALSE) {
		if (getFileExt($filename) == "jpg"){
			if ($file != "") {
				$nextfile = $filename; // 다음 이미지
				break;
			}
			if ($name == $filename) $file = $filename; // 현재이미지
			else $prevfile = $filename; // 이전이미지는 계속 겹쳐씀
		}
	}
	closedir($dir_handle);
	
	if ($prevfile == "") $prevfile = $file;
	if ($nextfile == "") $nextfile = $file;
	
	$src = $dir_path . "/" . $file;
	
	$size = getimagesize($src);
	$width = $size[0];
	
	$title = substr($file,0,strlen($file)-4);
	$exif = exif_info($dir_path . "/" . $file);
	
	echo "<table id=\"gallery\" width=\"" . $width . "\" align=\"center\"><tr><td>\n";
	echo "<a href=\"" . $src . "\" target=\"_blank\"><img src=\"" . $src . "\" border=\"0\" class=\"gimg\" /></a><br />\n";
	echo "<p class=\"label\">" . $title . "</p>\n";
	echo "<p class=\"exif\">" . $exif . "</p>\n";
	echo "<button onclick=\"location='?path=" . $path . "&name=" . $prevfile . "'\">이전</button> <button onclick=\"location='?path=" . $path . "&name=" . $nextfile . "'\">다음</button> <button onclick=\"location='gallery.php?path=" . $path . "'\">목록으로</button>";
	echo "</td></tr></table>";
?>
</body>
</html>